package com.zlzlib.libglide;

import android.content.Context;

import androidx.annotation.NonNull;

import com.bumptech.glide.Glide;
import com.bumptech.glide.GlideBuilder;
import com.bumptech.glide.Registry;
import com.bumptech.glide.module.AppGlideModule;

import okhttp3.Call;

/**
 * Created by zlz on 2019/9/26.
 * 配置glide 用我们自己的Okhttp  实例
 */
//继承的类需要写上 @GlideModule
public abstract class BaseGlideConfig extends AppGlideModule {

    @Override
    public void registerComponents(@NonNull Context context, @NonNull Glide glide, @NonNull Registry registry) {
        // 注意这里用我们 现有的Client实例传入即可
        GlideUtil.replaceOkHttp(registry, getClient());
    }


    /**
     * @return 设置清单解析，设置为false，避免添加相同的modules两次
     */
    @Override
    public boolean isManifestParsingEnabled() {
        return false;
    }

    @Override
    public void applyOptions(@NonNull Context context, @NonNull GlideBuilder builder) {
        super.applyOptions(context, builder);
    }

    protected abstract Call.Factory getClient();
}
